package com.dgut.app.controller;

import com.dgut.app.service.WishService;
import com.dgut.common.dto.WishDTO;
import com.dgut.common.utils.R;
import org.springframework.web.bind.annotation.*;

/**
 * @author IT00ZYQ
 * @Date 2021/4/5 13:20
 **/
@RequestMapping("/app/wish")
@RestController
public class WishController {
    private final WishService wishService;

    public WishController(WishService wishService) {
        this.wishService = wishService;
    }

    /**
     * 新增心愿
     * @param dto
     * @param token
     * @return
     */
    @PostMapping
    public R addWish(@RequestBody WishDTO dto, @RequestHeader("token") String token) {
        wishService.addWish(dto, token);
        return R.ok();
    }

    /**
     * 删除心愿
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public R deleteWish(@PathVariable("id") Integer id) {
        wishService.delete(id);
        return R.ok();
    }

    /**
     * 心愿详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public R detail(@RequestParam Integer id) {
        return R.ok().data("wish", wishService.detail(id));
    }

    /**
     * 用户心愿列表
     * @param token
     * @return
     */
    @GetMapping
    public R list(@RequestHeader("token") String token) {
        return R.ok().data("list", wishService.listWish(token));
    }

    /**
     * 修改心愿
     * @param dto
     * @return
     */
    @PutMapping
    public R update(@RequestBody WishDTO dto) {
        wishService.update(dto);
        return R.ok();
    }


}
